<?php
/**
 * Created by PhpStorm.
 * User: 丶晓
 * Date: 2017/8/29
 * Time: 15:48
 */

namespace app\home\controller;


use app\common\Qiniu\PlaySDK;
use app\home\common\Tools;
use think\Config;
use think\Cookie;
use think\Request;

class Common extends Tools
{
    // 前端接口获取上传Token
    public function getQiniuUploadToken()
    {
        if (Cookie::has('upload_token')) {
            return $this->success('request success', ['token' => Cookie::get('upload_token')]);
        }
        $qiniu = new PlaySDK(Config::get('qiniu.appid'), Config::get('qiniu.appsecret'));
        $token = $qiniu->getUpdataToken(Config::get('qiniu.bucket'));
        if ($token) {
            Cookie::set('upload_token', $token, 1800); // 设置缓存
            return $this->success('request success', ['token' => $token]);
        }
        return $this->error('request fail');
    }
}
